<?php

namespace App\Admin\Actions\Auction;

use App\Library\Logic\OperateLogLogic;
use App\Library\Models\AdminAuctionModel;
use App\Models\ShopProductModel;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;

class AuctionRecommendAction extends RowAction
{
    public function __construct(int $status = 0)
    {
        parent::__construct();
        $this->name = $status === 1 ? '取消推荐' : '推荐';
    }

    public function handle(AdminAuctionModel $model): Response
    {
        $model->recommend = (int)$model->recommend ? 0 : 1;
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.auction.recommend', ['recommend' => $model->recommend]);
        return $this->response()->success('操作成功')->refresh();
    }

    /**
     * dialog
     * @return void
     */
    public function dialog(): void
    {
        $this->confirm('确定操作吗?');
    }
}
